/**
 * ...
 * @author Krzysztof Rozalski
 */

package test;
import hapi.math.Angle;
import hapi.unit.HapiTestCase;
using hapi.math.AngleFactoryMethods;

class TestAngle extends HapiTestCase {

	public function testDegreesConstructor() {
		var alfa = 90.degrees();
		assertEquals(90., alfa.degrees);
		assertEquals(Math.PI/2, alfa.radians);
	}
	
	public function testRadiansConstructor() {
		var alfa = Math.PI.radians();
		assertEquals(180., alfa.degrees);
		assertEquals(Math.PI, alfa.radians);
	}
	
	public function test370Degress() {
		var alfa = 370.degrees();
		assertFloatEqualsWithTolerance(10., alfa.degrees);
	}
	
	public function testMinus360Degrees() {
		var alfa:Angle = (-360).degrees();
		assertEquals(0., alfa.degrees);
	}
	
	public function test360Degrees() {
		var alfa = 360.degrees();
		assertEquals(0., alfa.degrees);
	}
	
	public function testHalfPI() {
		var alfa = 0.5.piRadians();
		assertEquals(90., alfa.degrees);
		assertEquals(Math.PI*0.5, alfa.radians);
	}
	
	public function testAddition() {
		var a = 10.degrees();
		var b = 30.degrees();
		assertFloatEqualsWithTolerance(40.0, a.add(b).degrees);
	}
	
	public function testAdditionOver180() {
		var a = 170.degrees();
		var b = 20.degrees();
		a.add(b);
		assertEquals(-170., a.degrees);
	}
	
	public function testSubstract() {
		var a = 20.degrees();
		var b = 170.degrees();
		a.substract(b);
		assertFloatEqualsWithTolerance(-150., a.degrees);
	}
	
	public function testMultiply() {
		var a = 100.degrees().multiplyBy(4);//400 deg
		assertFloatEqualsWithTolerance(40.0, a.degrees);
	}
	
	public function testDivide() {
		var a = 100.degrees().divideBy(2);//-400 deg
		assertFloatEqualsWithTolerance(50.0, a.degrees);
	}
}